package com.wesley.fritesfinder.model;

import java.util.ArrayList;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.graphics.drawable.Drawable;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

public class MyItemizedOverlay extends ItemizedOverlay {
	private ArrayList<OverlayItem> overlays;
	private Context myContext;
	
	
	public MyItemizedOverlay(Drawable marker, Context context) {
		super(boundCenterBottom(marker));
		overlays = new ArrayList<OverlayItem>();
		//handle events
		myContext = context;
	}

	public void addOverlay(OverlayItem overlay) {
		overlays.add(overlay);
	}
	
	public void populateOverlay() {
		populate();
	}
	
	@Override
	protected OverlayItem createItem(int i) {
		return overlays.get(i);
	}

	@Override
	public int size() {
		return overlays.size();
	}
	
	@Override
	protected boolean onTap(int index) {
		OverlayItem item = overlays.get(index);
		Builder alertDialog = new AlertDialog.Builder(myContext);
		alertDialog.setTitle(item.getTitle());
		alertDialog.setMessage(item.getSnippet());
		alertDialog.show();
		return true;
	}

}
